// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#include <cantor/unresolved/ddls/alter_table_spec.h>
#include <cantor/unresolved/ddls/table_option.h>
#include <cantor/unresolved/ddls/column_def.h>
#include <cantor/unresolved/ddls/constraint.h>
#include <cantor/unresolved/ddls/partition_range.h>
#include <cantor/unresolved/dqls/where_clause.h>
#include <cantor/unresolved/clause/range_var.h>
#include <cantor/unresolved/clause/table_name.h>
#include <cantor/unresolved/dmls/assignment.h>
#include <cantor/unresolved/dispatch_expr.h>

namespace cantor::unresolved {
    /// check the expr visitor must in global traits list
    static_assert(unresolved::isInAllExprList<unresolved::UnresolvedAlterTableSpec>::value, "not in all visitor lists");

    std::vector<UnresolvedTableOption> UnresolvedAlterTableSpec::table_options() const {
        std::vector<UnresolvedTableOption> table_options;
        for (auto& option : instance.table_options()) {
            table_options.push_back(UnresolvedTableOption(option));
        }
        return table_options;
    }
    UnresolvedTableOption UnresolvedAlterTableSpec::table_option(size_t index) const {
        return instance.table_options(index);
    }

    UnresolvedTableName UnresolvedAlterTableSpec::new_table_name() const {
        return UnresolvedTableName{instance.new_table_name()};
    }

    std::vector<UnresolvedColumnDef> UnresolvedAlterTableSpec::new_column_defs() const {
        std::vector<UnresolvedColumnDef> columns;
        for (auto &item : instance.new_columns()) {
            columns.push_back(UnresolvedColumnDef(item));
        }
        return columns;
    }
    UnresolvedColumnDef UnresolvedAlterTableSpec::new_column_def(size_t index) const {
        return UnresolvedColumnDef(instance.new_columns(index));
    }

    std::vector<UnresolvedAssignment> UnresolvedAlterTableSpec::new_assignments() const {
        std::vector<UnresolvedAssignment> assignments;
        for (auto & item : instance.set_list()) {
            assignments.push_back(UnresolvedAssignment(item));
        }
        return assignments;
    }
    UnresolvedAssignment UnresolvedAlterTableSpec::new_assignment(size_t index) const {
        return UnresolvedAssignment(instance.set_list(index));
    }

     UnresolvedWhereClause UnresolvedAlterTableSpec::where_clause() const {
        return UnresolvedWhereClause(instance.where());
    }

    std::vector<UnresolvedConstraint> UnresolvedAlterTableSpec::new_constraints() const {
        std::vector<UnresolvedConstraint> constraints;
        for (auto &item : instance.new_constraints()) {
            constraints.push_back(UnresolvedConstraint(item));
        }
        return constraints;
    }
    UnresolvedConstraint UnresolvedAlterTableSpec::new_constraint(size_t index) const {
        return UnresolvedConstraint(instance.new_constraints(index));
    }

    UnresolvedPartitionRange UnresolvedAlterTableSpec::partition_range() const {
        return UnresolvedPartitionRange(instance.partition_range());
    }
}  // namespace cantor::unresolved
